﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CRC.GestionSalones.Controladores;
using CRC.Comun.Presentacion;

namespace CRC.GestionSalones.Presentacion
{
    public partial class ModificarSupCircuito : DlgPersona
    {
        private IControladorCongregacion iCC = null;

        public ModificarSupCircuito()
        {
            InitializeComponent();
        }

        public ModificarSupCircuito(IControladorCongregacion pICC) : this()
        {
            this.iCC = pICC;

            try
            {
                Object[] datosSupCircuito = this.iCC.obtenerDatosSuperintendenteCircuito();
                txtNombre.Text = (String)datosSupCircuito[0];
                txtApellido1.Text = (String)datosSupCircuito[1];
                txtApellido2.Text = (datosSupCircuito[2] != null) ? (String)datosSupCircuito[2] : null;
                txtTelfFijo.Text = (datosSupCircuito[3] != null) ? (String)datosSupCircuito[3] : null;
                txtTelfMovil.Text = (datosSupCircuito[4] != null) ? (String)datosSupCircuito[4] : null;
                txtEmail.Text = (datosSupCircuito[5] != null) ? (String)datosSupCircuito[5] : null;

            }
            catch (Exception ex) 
            {
                MessageBox.Show(
                    ex.Message,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1
                 );
            }
        }

        public override void butOK_Click(object sender, EventArgs e)
        {
            if (txtNombre.Text.Trim().Length == 0 ||
                txtApellido1.Text.Trim().Length == 0)
            {
                MessageBox.Show(
                    "Campos obligatorios por cumplimentar",
                    "Advertencia",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning,
                    MessageBoxDefaultButton.Button1
                );
            }
            else
            {
                try 
                {
                    this.iCC.modificarDatosSupCircuito(
                        txtNombre.Text.Trim(),
                        txtApellido1.Text.Trim(),
                        txtApellido2.Text.Trim(),
                        txtTelfMovil.Text.Trim(),
                        txtTelfFijo.Text.Trim(),
                        txtEmail.Text.Trim()
                    );
                }
                catch (Exception ex) 
                {
                    MessageBox.Show(
                        ex.Message,
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1
                     );
                }
            }
        }
    }
}
